﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace HRForm
{
    public partial class Form1 : Form
    {
        private string filepath = "";
        private string fileName1 = "";
        private string fileName = "";
        private string extendedName = "";



        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Stream myStream;
            //OpenFileDialog openFileDialog1 = new OpenFileDialog();

            //openFileDialog1.InitialDirectory = "c:\\";
            //openFileDialog1.Filter = "xls files (*.xls)|*.txt|All files (*.*)|*.*";
            //openFileDialog1.FilterIndex = 2;
            //openFileDialog1.RestoreDirectory = true;

            //if (openFileDialog1.ShowDialog() == DialogResult.OK)
            //{
            //    if ((myStream = openFileDialog1.OpenFile()) != null)
            //    {
            //        // Insert code to read the stream here.
            //        myStream.Close();
            //    }
            //}

                         //new一个方法
            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);  //定义打开的默认文件夹位置
            openFileDialog1.ShowDialog();          //显示打开文件的窗口
            fileName = openFileDialog1.FileName;               //获得选择的文件路径
            filepath = fileName;
            label1.Text = fileName;
            extendedName = Path.GetExtension(fileName);       //获得文件扩展名
            fileName1 = Path.GetFileName(fileName);           //获得文件名
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (filepath != String.Empty)
            {
                DataSet ds = ReadWriteExcel.LoadDataFromExcel(filepath);
                dataGridView1.DataSource = ds.Tables[0];
                Application.DoEvents();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count > 1) //控件中数据不为空
            {
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add("khh", "客户号");
                dic.Add("NEW_KHQC", "新客户卡号");
                dic.Add("NEW_JGZCRQ", "新机构时间");
                dic.Add("NEW_JGZCZB", "新机构zb");
                dic.Add("NEW_FRDBXM", "新法人xm");
                dic.Add("NEW_FRDBZJYXQ", "新法人xq");
                dic.Add("NEW_JBRXM", "新jbrxm");
                dic.Add("NEW_JBRZJYXQ", "新客户号xq");

                ReadWriteExcel.ExportTasks(dataGridView1, dic);
            }
        }


    }
}
